﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace Kiosk
{
    /// <summary>
    /// Interaction logic for MentorDisplayBox.xaml
    /// </summary>
    public partial class MentorDisplayBox : UserControl
    {
        private DataSet dsCurFavMentors;
        private int curFavMentorsCount;
        public MentorDisplayBox()
        {
            InitializeComponent();
            dsCurFavMentors = new DataSet();
            curFavMentorsCount = 0;
        }

        private void btnContactMentor_Click(object sender, RoutedEventArgs e)
        {            
            sGlobals.contactMentor.Show();
            sGlobals.mentorDisplay.Hide();
        }

        private void btnAddToFavorites_Click(object sender, RoutedEventArgs e)
        {
            string sql = "SELECT mentor_id FROM favorite_mentors WHERE user_id = (SELECT user_id FROM users " + "WHERE username = '" + sGlobals.currentUsername + "') AND mentor_id = '" + sGlobals.selectedMentorID + "'";
            try
            {
                dsCurFavMentors = sGlobals.dbWrapper.ExecuteSQLStatement(sql, ref curFavMentorsCount);
                if (curFavMentorsCount > 0)
                {
                    WarningMessage warn = new WarningMessage();
                    warn.lblMessage.Content = "This mentor is already in your favorites list!";
                    warn.ShowDialog();
                    return;
                }


                string addFavStatement = "INSERT INTO favorite_mentors (mentor_id, user_id) VALUES " +
                    "('" + sGlobals.selectedMentorID + "', (SELECT user_id FROM users " +
                    "WHERE username = '" + sGlobals.currentUsername + "'))";

                int returnVal = sGlobals.dbWrapper.ExecuteNonQuery(addFavStatement);
                if (returnVal < 1)
                {
                    WarningMessage warn = new WarningMessage();
                    warn.lblMessage.Content = "There was a problem adding the mentor to your favorites list";
                    warn.ShowDialog();
                }//end if
                else
                {
                    WarningMessage warn = new WarningMessage();
                    warn.lblMessage.Content = "The mentor was added to your favorites list";
                    warn.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                WarningMessage warn = new WarningMessage();
                warn.lblMessage.Content = "There was an issue adding the mentor to your favorites list.\r\nIf the problem persists, please contact your system administrator";
                warn.ShowDialog();
            }
        }
    }
}
